/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { Injectable } from '@angular/core';
import { Service } from '@api';
import { _HttpClient } from '@delon/theme';
import { environment } from '@env/environment';
import { Observable } from 'rxjs';

/**
 * 简单业务接口
 * @author maoxiaodong
 */
@Injectable()
export class SimpleService extends Service<any, string> {
  constructor(public http: _HttpClient) {
    super(http, `${environment.simple.ctx}/find`);
  }

  findById(id: any): Observable<any> {
    return this.http.get(`${this.baseUrl}/${id}`);
  }

  findByIds(ids: any[]): Observable<any[]> {
    return this.http.post(`${this.baseUrl}/list`, ids);
  }

  findAll(): Observable<any[]> {
    return this.http.get(`${this.baseUrl}/list`);
  }

  save(t: any): Observable<any> {
    return this.http.put(`${this.baseUrl}`, t);
  }

  saveAll(ts: any[]): Observable<any> {
    return this.http.put(`${this.baseUrl}/saveAll`, ts);
  }

  deleteById(id: any): Observable<number> {
    return this.http.delete(`${this.baseUrl}/${id}`);
  }

  deleteByIds(ids: any[]): Observable<number> {
    const options = {
      headers: {
        'Content-Type': 'application/json',
      },
      body: ids,
    };
    return this.http.delete(`${this.baseUrl}/list`, {}, options);
  }

  isUnique(t: any): Observable<boolean> {
    return this.http.post(`${this.baseUrl}/isUnique`, t);
  }

  findByQueryParams(params: any): Observable<any> {
    return this.http.get(this.baseUrl, params);
  }
}
